package com.aspirecn.core.object;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.math.NumberUtils;

public class ShortURL {

	// 成功
	public final static int OK = 200;
	// 不可用
	public final static int INVALID_KEY = 201;
	// 未知错误
	public final static int UNKNOWN_ERROR = 202;
	// 系统错误
	public final static int SYSTEM_ERROR = 203;
	// 短地址不合法
	public final static int USERSHORT_ILLEGAL = 204;
	// 短地址已存在
	public final static int ALREADY_USED = 205;
	// 长地址不存在
	public final static int LONG_UNEXIST = 206;
	// 长地址不合法
	public final static int LONG_ILLEGAL = 207;
	// Key和短地址不匹配，无法还原
	public final static int NOT_MATCH = 208;
	// 请求频率限制
	public final static int REQUEST_LIMIT = 209;

	private String longUrl;

	public String getLongUrl() {
		return longUrl;
	}

	public void setLongUrl(String longUrl) {
		this.longUrl = longUrl;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public String getStatus_txt() {
		return status_txt;
	}

	public void setStatus_txt(String status_txt) {
		this.status_txt = status_txt;
	}

	public String getUserShort() {
		return userShort;
	}

	public void setUserShort(String userShort) {
		this.userShort = userShort;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	private int status;
	private String status_txt;
	private String userShort;
	private String url;

	public String toString() {
		return ReflectionToStringBuilder.toString(this);
	}

	public void load(String jsonString) {
		this.longUrl = StringUtils.substringBetween(jsonString,
				"\"longUrl\":\"", "\"");
		this.status = NumberUtils.toInt(StringUtils.substringBetween(
				jsonString, "\"status\":", ","));
		this.status_txt = StringUtils.substringBetween(jsonString,
				"\"status_txt\":\"", "\"");
		this.userShort = StringUtils.substringBetween(jsonString,
				"\"userShort\":\"", "\"");
		this.url = StringUtils.substringBetween(jsonString, "\"url\":\"", "\"");
	}
}
